package com.useeinfo.oa.common.utils.httpJson;

import javax.servlet.http.HttpServletRequest;

/**
 * 默认处理是否需要返回json
 * @author geniusj
 * @email 975473185@qq.com
 * @date 2018/8/20  下午2:04
 */
public class DefaultJudgmentJson implements JudgmentJson{

    @Override
    public boolean isJson(HttpServletRequest request) {
        String contentTypeHeader = request.getHeader(CONTENT_TYPE);
        String acceptHeader = request.getHeader(ACCEPT);
        String xRequestedWith = request.getHeader(X_REQUESTED_WIDTH);
        boolean isAjax = (contentTypeHeader != null && contentTypeHeader.contains(APPLICATION_JSON))
                || (acceptHeader != null && acceptHeader.contains(APPLICATION_JSON))
                || XML_HTTP_REQUEST.equalsIgnoreCase(xRequestedWith);
        return isAjax;
    }
}
